<?php
/**
 * Created by 项目.
 * User: xuguopeng
 * Date: 2020-06-23
 * Time: 16:52
 */

namespace app\api\controller\v1;


use app\api\model\Admin;
use app\api\service\store\StaffClearOrderSer;
use app\api\service\store\StaffOrderSer;
use app\api\service\store\StaffPayOrderSer;
use app\api\service\Token;
use app\api\model\User;
use app\api\model\StoreOrder;

class Staff
{
    // 该门店未抢单订单列表
    public function getUnGrabOrder()
    {
        $user = User::get(Token::getCurrentUid());
        $staff = Token::judgeStaff($user);
        return StoreOrder::where('lin_user_id',$staff['lin_user_id'])
            ->where('status',1)
            ->order('id desc')
            ->select()->toArray();
    }

    // 取送员抢单操作
    public function grabOrder($order_id)
    {
        $staffOrder = new StaffOrderSer($order_id);
        return $staffOrder->entrance();
    }

    // 取送员清点取衣操作
    public function clearOrder($order_id,$price,$clean)
    {
       $cleanOrderSer = new StaffClearOrderSer($order_id,$price,$clean);
       return $cleanOrderSer->entrance();
    }

    // 取送员线下收款操作
    public function payOrder($order_id)
    {
        $StaffPayOrderSer = new StaffPayOrderSer($order_id);
        return $StaffPayOrderSer->entrance();
    }

    // 取送员订单列表
    public function getOrderList()
    {
        $user = User::get(Token::getCurrentUid());
        $staff = Token::judgeStaff($user);
        return StoreOrder::where('pick_deliver_staff_id',$staff['id'])
            ->order('id desc')
            ->select()->toArray();
    }

    // 取送员订单详情
    public function getOrderInfo($id)
    {
        $user = User::get(Token::getCurrentUid());
        $staff = Token::judgeStaff($user);
        return StoreOrder::with('clean')->where('pick_deliver_staff_id',$staff['id'])
            ->where('id',$id)
            ->find();
    }

    // 取送员数据中心  - 完成了多少单 多少正在送  总共多少钱
    public function getDataList()
    {
        $user = User::get(Token::getCurrentUid());
        $staff = Token::judgeStaff($user);
        $done_count = StoreOrder::where('pick_deliver_staff_id',$staff['id'])
            ->where('status',6)
            ->count();
        $undone_count = StoreOrder::where('pick_deliver_staff_id','eq',$staff['id'])
            ->where('status','lt',6)
            ->count();
        $total = StoreOrder::where('pick_deliver_staff_id','eq',$staff['id'])->sum('price');
        return [
            'done_count' => $done_count,
            'undone_count' => $undone_count,
            'total' => $total
        ];
    }
}